# Contributor: Fabricio Silva <hi@fabricio.dev>
# Maintainer: Fabricio Silva <hi@fabricio.dev>
pkgname=autoscan
pkgver=1.4.0
pkgrel=1
pkgdesc="Autoscan replaces the default Plex and Emby behaviour for picking up changes on the file system."
url="https://github.com/Cloudbox/autoscan"
arch="x86_64 aarch64 armv7"
license="MIT"
options="net" # for downloading Go modules
makedepends="go"
subpackages="$pkgname-openrc"
install="$pkgname.pre-install"
source="
	$pkgname-v$pkgver.tar.gz::https://github.com/Cloudbox/autoscan/archive/v$pkgver.tar.gz
	autoscan.initd
	autoscan.confd
	"

export CGO_ENABLED=0
export GOCACHE="${GOCACHE:-"$srcdir/go-cache"}"
export GOTMPDIR="${GOTMPDIR:-"$srcdir"}"
export GOMODCACHE="${GOMODCACHE:-"$srcdir/go"}"

build() {
	# strings used to parse "$Version ($GitCommit@$Timestamp)"
	local ldflags="
		-X main.Version=$pkgver
		-X main.GitCommit=alpine
		-X main.Timestamp=r$pkgrel
	"

	go build -ldflags "$ldflags" -o bin/autoscan ./cmd/autoscan
}

check() {
	go test ./...
}

package() {
	install -Dm755 bin/autoscan -t "$pkgdir"/usr/bin

	install -Dm755 "$srcdir"/$pkgname.initd "$pkgdir"/etc/init.d/$pkgname
	install -Dm644 "$srcdir"/$pkgname.confd "$pkgdir"/etc/conf.d/$pkgname
}

sha512sums="
4527a988797fcee2049e0d9c00a4544948c056d30402abefc9bedfa7b0c5d6e141c3ec9c23caefea3875378db2ba0cdc99cc1bed12aca2e66fc908af8296a133  autoscan-v1.4.0.tar.gz
d567c68c0b346c96292dad19389f7c4a83609aae406f577d7cca9a1b2a336de3044224cb252ddb9a49dab874182e9a05fd549f102ad39ff12cc3b30bedf6a061  autoscan.initd
7d1e0accbe7c5e7fe26652bd234ad4b7e5877c640ddf15cf5d1f6c621d1e7d1a5729af270414ddddaed4f0eee51ca88dd403f81fadb10fcc403100f56fd42629  autoscan.confd
"
